public class test2 {
    public static int findGreatestSumOfSubArray(int[] data) {
        if (data == null || data.length == 0) {
            return 0;
        }
        int curSum = 0;
        int greatestSum = Integer.MIN_VALUE;

        for (int i = 0; i < data.length; i++) {
            if (curSum <= 0) {
                curSum = data[i];
            }
            else {
                curSum += data[i];
            }

            if (curSum > greatestSum) {
                greatestSum = curSum;
            }
        }

        return greatestSum;
    }

    public static void main(String[] args) {
        int[] data = {1,-2,3,10,-4,7,2,-5};
        System.out.println(findGreatestSumOfSubArray(data));

    }

}
